package com.example.basefream.config;

import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import org.springframework.stereotype.Component;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import javax.annotation.Resource;

/**
 * @author ：Mr-L
 * @date ：Created in 2022/4/13 10:40
 * @description：实时刷新监听的键
 * @modified By：
 * @version: $
 */
@Component
public class ConfigRefresh {
    @Resource
    private DevConfig devConfig;

    @Resource
    private RefreshScope refreshScope;

    @ApolloConfigChangeListener("application,TONG.fream")
    public void onChange(ConfigChangeEvent changeEvent) {
        boolean configChange = false;
        for (String ckey : changeEvent.changedKeys()) {
            if (ckey.startsWith("tong")) {
                configChange = true;
                break;
            }
        }
        if (!configChange) {
            return;
        }
        refreshScope.refresh("devConfig");
    }

}
